<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>username</title>
</head>

<body>
用户名<input type="text" id="user" onblur="fn()" /><label id="check"></label>
</body>
</html>
<script>
var xmlHttp;
var str;
var test;
function fn(){
	str = 'usercode.asp?username='+document.getElementById('user').value;
	startRequest(str);
}

function createXMLHttpRequest(){
	if(window.ActiveXObject){
		xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
	}else{
		xmlHttp = new XMLHttpRequest();	
	}
}
function startRequest(url){
	createXMLHttpRequest();
	xmlHttp.onreadystatechange = handleStateChange;
	xmlHttp.open('GET',url,true);
	xmlHttp.send(null);	
}
function handleStateChange(){
	if(xmlHttp.readyState == 4){
		if(xmlHttp.status == 200){
			var oBox = document.getElementById('check')
			test=eval('('+xmlHttp.response+')');  
			switch (test.Error){
				case 300:{
					oBox.style.color = '#ff0000';
					oBox.innerHTML = test.str+'推荐使用下列名字：';
					for(n in test.Altern){
						oBox.innerHTML+=test.Altern[n]+'&nbsp;';	
					}
					break;
				}
				case 500:{
					oBox.style.color = '#ff0000';
					oBox.innerHTML = test.str;
					break;
				}
				case 200:{
					oBox.style.color = '#00ff00';
					oBox.innerHTML = test.str;	
					break;
				}
				
			}
		}
	}
}
</script>